package com.geekgo.flowcontroller.core.acquire;

import com.google.common.util.concurrent.RateLimiter;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * @author geekgo
 * @version 2016/8/4 10:17
 */
public class QPSLimitAcquirable extends RateLimitAcquirable {

    private static final Logger LOGGER = LogManager.getLogger(QPSLimitAcquirable.class);
    private int acquire;

    public QPSLimitAcquirable(RateLimiter rateLimiter,int acquire) {
        super(rateLimiter);
        this.acquire= acquire;
    }

    @Override
    public void acquire(Object[] args) {
        int acquire = getAcquire();
        LOGGER.debug("acquire for {}",acquire);
        double s = getRateLimiter().acquire(acquire);
        LOGGER.info("耗时{}",s);
    }

    public int getAcquire() {
        return acquire;
    }

    public void setAcquire(int acquire) {
        this.acquire = acquire;
    }
}
